/*
 * ThinkGraphJPanel.java
 *
 * Created on 09.02.2009, 14:59:14
 */

package morenoapp.components.thinkgraph;

import java.awt.BorderLayout;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.JScrollPane;
import morenoapp.MorenoApp;
import morenoapp.components.thinkgraph.model.DisplayFilter;
import morenoapp.model.app.MorenoApplicationListener;
import morenoapp.model.listeners.MorenoModelAdapter;

/**
 *
 * @author dmitry.mamonov
 */
public class ThinkGraphJPanel extends javax.swing.JPanel {
    protected DisplayFilter filter;
    protected PiccoloGraph piccoloGraph;
    ThinkGraphDisplayFilterJPanel filterPanel;
    /** Creates new form ThinkGraphJPanel */
    public ThinkGraphJPanel() {
        initComponents();

        //my code
        setLayout(new BorderLayout(0,0));
        filter = new DisplayFilter();
        piccoloGraph = new PiccoloGraph(filter);
        filter.setGraph(piccoloGraph);
        filterPanel = new ThinkGraphDisplayFilterJPanel(filter);

        add(piccoloGraph,BorderLayout.CENTER);

        JScrollPane filterScrollPane = new JScrollPane(filterPanel);
        filterScrollPane.getVerticalScrollBar().setUnitIncrement(16);
        filterScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        filterScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        add(filterScrollPane, BorderLayout.EAST);

        addComponentListener(new ComponentAdapter() {
            @Override
            public void componentShown(ComponentEvent e) {
                refreshView();
            }
        });

        MorenoApp.getApplicationData().getMorenoModelProxy().addModelListener(new MorenoModelAdapter(){
            @Override
            public void onWholeModelChanged() {
                refreshView();
            }
        });
    }

    private void refreshView(){
            piccoloGraph.loadGraphDataFromModel();
            filterPanel.refreshFilter();
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setName("Form"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
